//
//  LanguageTableViewDelegator.m
//  LanguagesTeach
//
//  Created by Niel Santos on 2/9/13.
//  Copyright 2013 __MyCompanyName__. All rights reserved.
//

#import "LanguageTableViewDelegator.h"
#import "RowTableCell.h"
#import "SubjectPath.h"
#import "UnitsController.h"
#import "SubjectsController.h"

@implementation LanguageTableViewDelegator

@synthesize navigationController;

- (id)init:(SubjectPath*) initSubjectPath {
	
    if (self = [super init]){
		subjectPath = initSubjectPath;
    }
    return self;		
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
	RowTableCell *cell;
	
	UnitsController *unitsController;
	SubjectsController *subjectsController;
	
	
	cell = (RowTableCell*)[tableView cellForRowAtIndexPath:indexPath];
	if((subjectPath.levelFolder) == nil){
		unitsController = [[UnitsController alloc] initWithNibName:@"Languages" bundle:nil];
		subjectPath.levelFolder = [cell prefix];
		unitsController.subjectPath = subjectPath;
		// Pass the selected object to the new view controller.
		[self.navigationController pushViewController:unitsController animated:YES];
		[unitsController release];
	}else {
		subjectsController =  [[SubjectsController alloc] initWithNibName:@"Languages" bundle:nil];
		subjectPath.unitSubFolder = [cell prefix];
		subjectsController.subjectPath = subjectPath;
		[self.navigationController pushViewController:subjectsController animated:YES];
		[subjectsController release];
	}
	[tableView deselectRowAtIndexPath:indexPath animated:YES];
}



@end
